package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
   Servlet处理类

   完成：
   一个servlet实现多个功能
 */
public class DemoServlet extends HttpServlet {
    /*
       既可以接受get请求也可以接受post请求
       自调用方法
     */

    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("service...");
        //获取method的值
        String method =req.getParameter("method");
        //判断执行的方法
        if("findAll".equals(method)){
            findAll(req,resp);
        }
        if("save".equals(method)){
            save(req,resp);
        }
        if("upDate".equals(method)){
            update(req,resp);
        }
    }

    private void findAll(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
        System.out.println("findAll");
    }
    private void save(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
        System.out.println("save");
    }
    private void update(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
        System.out.println("update");
    }
}
